<?php
namespace Home\Controller;

class GoodsController extends CommonController{

	public function index(){
        $goods = D('Goods')->where("is_on_sale='1'")->order('sort_order ASC')->select();
        $packages = D('GoodsActivity')->select();
        
        $this->assign('goods',$goods);
        $this->assign('packages',$packages);
	    $this->display();
    }

    public function package(){
        
        $this->display();
    }

    public function goods_detail(){
        $goods_id = intval(I('get.goods_id'));
        $goods_data = D('Goods')->where(array('goods_id'=>$goods_id))->find();
        $keywords = explode(' ', $goods_data['keywords']);
        //评论数据
        $comments = D('Comment')->where("id_value='$goods_id' and comment_type=0")->order("add_time desc")->select();
        //获取组合套餐
        $gwhere = array();
        $gwhere['type'] = '0';
        $gwhere['addr'] = '1';
        $gwhere['parent_id'] = $goods_id;
        $group_goods = D('GroupGoods')->relation(true)->where($gwhere)->select();

        $this->assign('group_goods',$group_goods);
        $this->assign('goods_data',$goods_data);
        $this->assign('keywords',$keywords);
        $this->assign('comment',$comments);
        $this->display();
    }
    
    public function package_detail(){
        $goods_id = intval(I('get.goods_id'));
        $goods_data = D('GoodsActivity')->where(array('act_id'=>$goods_id))->find();
        $goods_data['ext_info'] = unserialize($goods_data['ext_info']);
        $keywords = explode(' ', $goods_data['kwords']);
        //套餐内容
        $package_goods = D('PackageGoods')->relation(true)->where("package_id='$goods_id'")->select();
        $package_detail = array();
        foreach ($package_goods as $key=>$val){
            $package_detail[] = $val['goods']['goods_name'];
        }
        $this->assign('package_detail',implode('、', $package_detail));
        //评论数据
        $comments = D('Comment')->where("id_value='$goods_id' and comment_type=0")->order("add_time desc")->select();
        //获取组合套餐
        $gwhere = array();
        $gwhere['type'] = '1';
        $gwhere['addr'] = '1';
        $gwhere['parent_id'] = $goods_id;
        $group_goods = D('GroupGoods')->relation(true)->where($gwhere)->select();
        //可选服务
        $permits = D('Goods')->where("goods_id IN('120','121','122')")->order('goods_id asc')->select();
        
        $this->assign('group_goods',$group_goods);
        $this->assign('goods_data',$goods_data);
        $this->assign('keywords',$keywords);
        $this->assign('comments',$comments);
        $this->assign('permits',$permits);
        $this->display();
    }
    
}
